package com.ruoyi.web.controller.counter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.counter.domain.Thtype;
import com.ruoyi.counter.service.IThtypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物品类型Controller
 *
 * @author xll
 * @date 2021-07-26
 */
@RestController
@RequestMapping("/counter/thtype")
public class ThtypeController extends BaseController
{
    @Autowired
    private IThtypeService thtypeService;

    /**
     * 查询物品类型列表
     */
    @PreAuthorize("@ss.hasPermi('counter:thtype:list')")
    @GetMapping("/list")
    public TableDataInfo list(Thtype thtype)
    {
        startPage();
        List<Thtype> list = thtypeService.selectThtypeList(thtype);
        return getDataTable(list);
    }

    /**
     * 导出物品类型列表
     */
    @PreAuthorize("@ss.hasPermi('counter:thtype:export')")
    @Log(title = "物品类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Thtype thtype)
    {
        System.out.println(thtype.toString());



        List<Thtype> list = thtypeService.selectThtypeList(thtype);
        ExcelUtil<Thtype> util = new ExcelUtil<Thtype>(Thtype.class);
        return util.exportExcel(list, "物品类型数据");
    }


    /**
     * 获取物品类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('counter:thtype:query')")
    @GetMapping(value = "/{thid}")
    public AjaxResult getInfo(@PathVariable("thid") Long thid)
    {
        return AjaxResult.success(thtypeService.selectThtypeById(thid));
    }

    /**
     * 新增物品类型
     */
    @PreAuthorize("@ss.hasPermi('counter:thtype:add')")
    @Log(title = "物品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Thtype thtype)
    {
        return toAjax(thtypeService.insertThtype(thtype));
    }

    /**
     * 修改物品类型
     */
    @PreAuthorize("@ss.hasPermi('counter:thtype:edit')")
    @Log(title = "物品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Thtype thtype)
    {
        return toAjax(thtypeService.updateThtype(thtype));
    }

    /**
     * 删除物品类型
     */
    @PreAuthorize("@ss.hasPermi('counter:thtype:remove')")
    @Log(title = "物品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{thids}")
    public AjaxResult remove(@PathVariable Long[] thids)
    {
        return toAjax(thtypeService.deleteThtypeByIds(thids));
    }
}
